Fix IUO type rendering so T! no longer generates T?!#354
Merged
Conversation
Mockolo parses an implicitly-unwrapped optional (`Int!`) as `Optional<Int>` with an `isIUO` flag, and `SwiftType.description` rendered its single optionality twice — the optional-sugar case appended `?` and the `isIUO` block appended `!` — producing `Int?!` (≈ `Int??`), which does not satisfy the `Int!` (≡ `Int?`) protocol requirement, so the generated mock failed to conform. This was pre-existing; no fixture exercised an IUO declaration (compiled `@Fixture` mocks surfaced it). - Properties: suppress the duplicate `?` for IUO in the optional-sugar case; the `isIUO` block still appends `!`, so the type renders `Int!`. Inert for everything else — plain `Int?` is unchanged, and the intentional `SomeProtocol!` force-unwrap backings go through the default nominal branch. - Functions / subscripts / generic returns: `!` is illegal inside a closure type, so the synthesized handler closure (`((Int!) -> Int!)?`) was non-compiling. Clear `isIUO` on the handler's argument and return types in `toClosureType` so they render as plain optionals (`((Int?) -> Int?)?`, legal), while the declared signature keeps `Int!` and still conforms. Clearing `isIUO` is a no-op for non-IUO types, so no existing handler changes. Adds compiled fixtures proving conformance: `iuoVars` (get-only + get-set) in TestVars and `iuoFuncs` (func param/return + subscript) in TestFuncs. No existing fixture output changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sidepelican
approved these changes
Jun 10, 2026
sidepelican
left a comment
Collaborator
There was a problem hiding this comment.
Nice catch! This makes for a good bug fix.
farkasseb
added a commit
to farkasseb/mockolo
that referenced
this pull request
Jun 10, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Split out of #353 per review. Mockolo renders an implicitly-unwrapped optional (
T!) asT?!(≈T??), which doesn't satisfy theT!(≡T?) protocol requirement — so the generated mock fails to conform.Fixed for properties, function/subscript params & returns, and generic returns. For func/subscript handlers the synthesized closure renders
((Int?) -> Int?)?(since!is illegal inside a closure type) while the signature keepsInt!. Inert for non-IUO types — no existing fixture output changes.Test plan
New
iuoVars/iuoFuncscompiled@Fixturemocks (conformance is compiler-enforced).swift build && swift testgreen.#353 carries an extra getter-on-IUO edge test that depends on this fix, so this should land first.
🤖 Generated with Claude Code